package com.ticket.sass.provider.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ticket.sass.common.entity.tenant.FilmEntity;
import com.ticket.sass.provider.dto.input.film.FilmListInput;
import com.ticket.sass.provider.mapper.FilmMapper;
import com.ticket.sass.provider.service.BaseService;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ywb
 * @since 2024-03-07
 */
@Service
public class FilmServiceImpl extends ServiceImpl<FilmMapper, FilmEntity> implements BaseService<FilmEntity> {
    public IPage<FilmEntity> iPage(FilmListInput input) {
        // 创建分页对象，传入当前页码和每页记录数
        Page<FilmEntity> page = new Page<>(input.getPageNum(), input.getPageSize());
        
        // 构建查询条件
        QueryWrapper<FilmEntity> queryWrapper = new QueryWrapper<>();
        if (input.getName() != null && !input.getName().isEmpty()) {
            queryWrapper.like("name", input.getName());
        }
        if (input.getType() != null && !input.getType().isEmpty()) {
            queryWrapper.like("type", input.getType());
        }
        if (input.getCode() != null && !input.getCode().isEmpty()) {
            queryWrapper.inSql("id", "SELECT film_id FROM film_versions WHERE code LIKE '%" + input.getCode() + "%' AND film_versions.deleted_at IS NULL");
        }
        queryWrapper.orderByDesc("id");
        
        // 执行分页查询
        return this.page(page, queryWrapper);
    }
}
